<template>
  <div>
    <questionnaire-detail-dynamic-and-static v-if="isShow && tempType === 'flexible'" :tempId="tempId"></questionnaire-detail-dynamic-and-static>
    <questionnaire-detail v-if="isShow && (tempType === 'static' || tempType === 'dynamic')" :tempId="tempId"></questionnaire-detail>
  </div>
</template>
<script>
  import questionnaireDetail from './questionnaireDetail.vue'
  import questionnaireDetailDynamicAndStatic from './questionnaireDetailDynamicAndStatic.vue'
  export default {
    name: 'questionnaireSetIndex',
    data () {
      return {
        isShow: false,
        tempType: 'static'
      }
    },
    components: {
      questionnaireDetailDynamicAndStatic,
      questionnaireDetail
    },
    props: {
      tempId: {
        type: String,
        default: ''
      }
    },
    watch: {
      tempId () {
        this.isShow = false
        this.$store.dispatch('getQuestionnaireTempById', {_id: this.tempId}).then(res => {
          if (res.success) {
            this.tempType = res.data.type || 'static'
            this.isShow = true
          }
        })
      }
    },
    beforeMount () {
      this.isShow = false
      this.$store.dispatch('getQuestionnaireTempById', {_id: this.tempId}).then(res => {
        if (res.success) {
          this.tempType = res.data.type || 'static'
          this.isShow = true
        }
      })
    }
  }
</script>
